/**
 *  FloatItem.java : IceBird project
 *  18:34:45 
 */
package icebird.compiler.x86.old;

import icebird.metadata.BasicType;
import icebird.compiler.x86.old.X86Register.GPR;

/**
 * @author Sergey Shulepoff[Knott]
 */
public final class FloatItem extends WordItem {
	
	private float value;

	/**
	 * @param owner
	 */
	public FloatItem(ItemFactory owner) {
		super(owner);
	}
	
	public final void init(EmitterContext c, byte k, short bp, X86Register reg, float v) {
		super.init(c, k, reg, bp);
		value = v;
	}
	
	public float getValue() {
		return value;
	}

	/* (non-Javadoc)
	 * @see icebird.compiler.x86.WordItem#cloneConstant(icebird.compiler.x86.EmitterContext)
	 */
	@Override
	protected WordItem cloneConstant(EmitterContext ec) {
		return creator.createFConst(ec, value);
	}

	/* (non-Javadoc)
	 * @see icebird.compiler.x86.WordItem#loadToConstant(icebird.compiler.x86.EmitterContext, icebird.compiler.x86.X86Assembler, icebird.compiler.x86.X86Register.GPR)
	 */
	@Override
	protected void loadToConstant(EmitterContext ec, X86Assembler os, GPR reg) {
		os.moveConst(reg, Float.floatToIntBits(value));
	}

	/* (non-Javadoc)
	 * @see icebird.compiler.x86.WordItem#popFromFPU(icebird.compiler.x86.X86Assembler, icebird.compiler.x86.X86Register.GPR, int)
	 */
	@Override
	protected void popFromFPU(X86Assembler os, GPR reg, int disp) {
		os.fst(reg, disp);
	}

	/* (non-Javadoc)
	 * @see icebird.compiler.x86.WordItem#pushConstant(icebird.compiler.x86.EmitterContext, icebird.compiler.x86.X86Assembler)
	 */
	@Override
	protected void pushConstant(EmitterContext ec, X86Assembler os) {
		os.push(Float.floatToIntBits(value));
	}

	/* (non-Javadoc)
	 * @see icebird.compiler.x86.WordItem#pushToFPU(icebird.compiler.x86.X86Assembler, icebird.compiler.x86.X86Register.GPR, int)
	 */
	@Override
	protected void pushToFPU(X86Assembler os, GPR reg, int disp) {
		os.fld(reg, disp);
	}

	/* (non-Javadoc)
	 * @see icebird.compiler.x86.Item#getType()
	 */
	@Override
	public BasicType getType() {
		return BasicType.Float;
	}
}
